package com.tdam2014.grupo02;

import java.util.ArrayList;

import com.tdam2014.grupo02.Picture;
import com.tdam2014.grupo02.R;
import com.tdam2014.grupo02.R.drawable;
//import com.tdam2014.grupo02.FolderAdapter.Holder;

import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;

public class PictureAdapter extends BaseAdapter {
	
	private ArrayList<Picture> list;
	private LayoutInflater inflater;

	public PictureAdapter(Context context) {
		inflater = LayoutInflater.from(context);
	}

	public void setList(ArrayList<Picture> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;

		if (convertView == null) 
		{
			convertView = inflater.inflate(R.layout.picture_list_item, null);
			holder = new Holder();
			holder.name = (TextView) convertView.findViewById(R.id.txtPicture);
			holder.date = (TextView) convertView.findViewById(R.id.txtDate);
			holder.description = (TextView) convertView.findViewById(R.id.txtDescription);
			holder.photo = (ImageView) convertView.findViewById(R.id.img_picture);
			convertView.setTag(holder);
		} 
		else 
		{
			holder = (Holder) convertView.getTag();
		}

		TextView name = holder.name;
		TextView date = holder.date;
		TextView description = holder.description;
		ImageView photo = holder.photo;
		
		Picture picture = list.get(position);
		
		name.setText(picture.getPictureName());
		name.setTypeface(null, Typeface.BOLD);
		date.setText(picture.getPictureDate().toString());
		photo.setImageResource(drawable.ic_action_picture);
		description.setText(picture.getPictureDescription());
		
		LinearLayout.LayoutParams params = (LayoutParams) holder.name.getLayoutParams();

		holder.name.setLayoutParams(params);
		return convertView;
	}

	private static class Holder {
		TextView name, date, description;
		ImageView photo;
		
	}

}
